package cc.ufinity.networkdiagnose.app;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.http.client.HttpClient;

import android.app.Activity;
import cc.ufinity.networkdiagnose.manager.ChinaNetAuthManager;
import cc.ufinity.networkdiagnose.manager.DBManager;
import cc.ufinity.networkdiagnose.manager.RandomGUID;
import cc.ufinity.networkdiagnose.manager.SimpleFTP;
import cc.ufinity.networkdiagnose.manager.Task;
import cc.ufinity.networkdiagnose.manager.UnicomWebAuthManager;
import cc.ufinity.networkdiagnose.manager.WebAuth;
import cc.ufinity.networkdiagnose.widget.FtpTestProxyWidget;
import cc.ufinity.networkdiagnose.widget.TaskTestGSMWidget;
import cc.ufinity.networkdiagnose.widget.TaskTestTDWidget;
import cc.ufinity.networkdiagnose.widget.TaskTestWlan2Widget;
import cc.ufinity.networkdiagnose.widget.TaskTestWlanWidget;
import cc.ufinity.networkdiagnose.widget.Task_Test_Widget;
import cc.ufinity.networkdiagnose.widget.Test_Task_Widget_GSM;
import cc.ufinity.networkdiagnose.widget.Test_Task_Widget_Other;
import cc.ufinity.networkdiagnose.widget.Test_Task_Widget_Other2;
import cc.ufinity.networkdiagnose.widget.Test_Task_Widget_TD;
import cc.ufinity.networkdiagnose.widget.Test_Task_Widget_Wlan;
import cc.ufinity.networkdiagnose.widget.Test_Task_Widget_Wlan2;

public class GlobalApp {
	public static boolean DEBUG = true;
	/**
	 * ==1福建
	 * ==2西藏
	 * ==3 江苏
	 * 
	 * 、。。
	 */
	public static int servlet=1;
	
	public static String FtpSerevrName="hfzc",FtpSerPassword="rjy217219";
	public static int FtpSerVerPort=21;
	public static String gsmTssi="";
	public static  String tdRrri="";
	public static int tdCi,tdLAc;
	public static int GsmCi,GsmLAc;
	
	
	
	
	/**经度*/
	public static String longitude="0.0";
	/**纬度*/
	public static  String latitude="0.0";
	
	//获取 city 、 town
	public static String url_ReturnAPinfo = "http://221.130.165.252/Task/ReturnApInfoXML.aspx?";  //Lac=22027&CI=11863
	public static String url_UpdateAPK = "http://221.130.165.252/task/UpdateAPK.aspx";
	public static String url_GetCityBuyPhone = "http://221.130.165.252/Task/GetCityBuyPhone.aspx?TaskPhone="; //15105506116
	
	public final static String NET_TEST = "网络测试";
	public final static String TASK_TEST = "任务测试";
	public final static String CHECK_TEST = "验收测试"; 
	public static String GUID = (new RandomGUID()).valueAfterMD5;
	private static boolean isNET_TEST = false;
	private static boolean isTASK_TEST  = false;
	private static boolean isCHECK_TEST = false;
	public static boolean isWlanTO_TD_GSM = false;
	
	
	public final static String CFG_SERVER = "cfgServer";
	public final static String CFG_SERVER_IP = "cfgServerIP";
	public final static String CFG_SERVER_PORT = "cfgServerPort";
	
	
	public static String FTP;
	
	
	public final static String ftp_GUID= (new RandomGUID()).valueAfterMD5;
	public static ChinaNetAuthManager chinaNetAuthManager;
    public static UnicomWebAuthManager unicomAuthManager;
    
    public static FtpTestProxyWidget ftpTestProxyWidget;
    public static String fileNameWlanUp = "1.log";
    public static String fileNameWlanDown = "2M.doc";
    public static int fileSizeWlanDown = 2097152;
    public static String fileNameTDUp = "GSM.log";
//    public static String fileNameTDDown = "2M.doc";
//    public static int fileSizeTDDown = 2097152;
    public static String fileNameTDDown = "1M.doc";
    public static int fileSizeTDDown = 1048576;
    public static String fileNameGSMUp = "GSM.log";
    public static String fileNameGSMDown = "300k.doc";
    public static int fileSizeGSMDown = 307200;
    
    public static String fileNameLargerDown = "200M.doc";
    public static final int fileSizeLargerDown = 200 * 1024 * 1024;
	/**
	 * 若已成功获取FTP信息，则不再定时获取FTP信息
	 */
	public static boolean isGotFtp = false;
	public static String who_to_CameraWidget = "";
	
	public static boolean isPeapTested = false;
	public static boolean canUse = true;
	
	/**
	 * 正在使用的网络类型
	 * 1:Wlan   2:TD   3:GSM
	 */
	public static int nowNetType = 0;
	/**
	 * 是否为Wlan流程
	 */
	public static boolean isWlanFirst = false;
	/**
	 * 先测的是TD网络还是GSM网络
	 * "" ：还未测试
	 * "HSDPA" : TD网络先测
	 * "EDGE" : GSM网络先测
	 */
	public static String TDorGSM_test = "";
	/**
	 * 先测的是TD网络还是GSM网络
	 * "" ：还未测试
	 * "HSDPA" : TD网络先测
	 * "EDGE" : GSM网络先测
	 */
	public static String TDorGSM_task = "";
	
	
	public static Map<String, String> logoutParas;
	public static String logoutUrl;
	public static HttpClient client;
	
	
	public static String username="8";
	public static String password="8";
	public static String wlanacip="8";
	public static String wlanacname="8";
	public static String wlanuserip="8";
	public static String logonsessid="8";
	public static String loginurl="8";
	
	public static String otherNet_ip ="";
	public static String otherNet_realIp ="";
	public static String otherNet_logoutParamStr ="";
	
	public static String city ="";
	public static String town ="";
	public static String CITY = "";
	
	public static boolean is_NET_TEST = true;
	public static boolean is_TASK_TEST = false;
	public static boolean is_CHECK_TEST = false;
	
	public static Task taskWlan = new Task();
	public static Task taskTD = new Task();
	public static Task taskGSM = new Task();
	public static Task taskOther = new Task();
	public static Task task_TASK = new Task();
	
	
	public static List<Task> taskOtherList = new ArrayList<Task>();
	public static int index = 0;
	
	//控制流程消息Handler--Message
	public static Test_Task_Widget_Other test_Task_Widget_Other;
	public static Test_Task_Widget_Other2 test_Task_Widget_Other2;
	public static Test_Task_Widget_GSM test_Task_Widget_GSM;
	public static Test_Task_Widget_TD test_Task_Widget_TD;
	public static Test_Task_Widget_Wlan test_Task_Widget_Wlan;
	public static Test_Task_Widget_Wlan2 test_Task_Widget_Wlan2;
	public static TaskTestGSMWidget taskTestGSMWidget;
	public static TaskTestTDWidget taskTestTDWidget;
	public static TaskTestWlanWidget taskTestWlanWidget;
	public static TaskTestWlan2Widget taskTestWlan2Widget;
	public static Task_Test_Widget task_Test_Widget;
	
	public static SimpleFTP simpleFtp;
	
	public static StringBuffer result_HTTP_test = new StringBuffer();    //HTTP测试
	public static StringBuffer result_FTP_test = new StringBuffer();     //FTP测试
	public static StringBuffer result_PING_test = new StringBuffer();    //PING测试
	public static StringBuffer result_AP_test = new StringBuffer();      //AP关联
	public static StringBuffer result_WEB_test = new StringBuffer();     //WEB认证
	public static StringBuffer result_PEAP_test = new StringBuffer();    //PEAP认证
	public static StringBuffer result_SIM_test = new StringBuffer();     //SIM认证
	public static StringBuffer result_SRRI_test = new StringBuffer();    //信号强度
	public static StringBuffer result_SNR_test = new StringBuffer();     //信噪比
	public static StringBuffer result_SEGREGATE_test = new StringBuffer();//隔离测试
	public static StringBuffer result_ROAM_test = new StringBuffer();    //漫游测试
	
	/**
	 * 1:网络测试   2:任务测试   3:验收测试
	 * @return
	 */
	public static int getTestType() {
		if(isNET_TEST) {
			return 1;
		} else if(isTASK_TEST) {
			return 2;
		} else if(isCHECK_TEST) {
			return 3;
		}
	
		return 0;
	}
	/**
	 * 1:网络测试   2:任务测试   3:验收测试
	 * @param flag
	 * @return
	 */
	public static boolean setTestType(int flag) {
		switch(flag) {
		case 1:
			isNET_TEST = true;
			isTASK_TEST = false;
			isCHECK_TEST = false;
			return true;
		case 2:
			isNET_TEST = false;
			isTASK_TEST = true;
			isCHECK_TEST = false;
			return true;
		case 3:
			isNET_TEST = false;
			isTASK_TEST = false;
			isCHECK_TEST = true;
			return true;
		default:
			return false;
		}
	}
	
	
	
	public static List<Task> taskTestList = new ArrayList<Task>();
	public static List<Task> taskTestList2 = new ArrayList<Task>();
	public static int getTestedApBumById(String taskId){
		List<Task> list = new ArrayList<Task>();
		for(int i=0;i<taskTestList.size();i++){
			Task task = taskTestList.get(i);
			if (task.id .equals(taskId)) {
				return task.testedAp.size();
			}
		}
		return 0;
	} 
	
	public static int getTestedNumById(String taskId){
		List<Task> list = new ArrayList<Task>();
		for(int i=0;i<taskTestList2.size();i++){
			Task task = taskTestList2.get(i);
			if (task.id .equals(taskId)) {
				return task.testedNum;
			}
		}
		return 0;
	} 
	
	/**
	 * 清除【查看】结果
	 */
	public static void clearAll() {
		result_HTTP_test = new StringBuffer();    //HTTP测试
		result_FTP_test = new StringBuffer();     //FTP测试
		result_PING_test = new StringBuffer();    //PING测试
		result_AP_test = new StringBuffer();      //AP关联
		result_WEB_test = new StringBuffer();     //WEB认证
		result_PEAP_test = new StringBuffer();    //PEAP认证
		result_SIM_test = new StringBuffer();     //SIM认证
		result_SRRI_test = new StringBuffer();    //信号强度
		result_SNR_test = new StringBuffer();     //信噪比
		result_SEGREGATE_test = new StringBuffer();//隔离测试
		result_ROAM_test = new StringBuffer();    //漫游测试
	}

	public GlobalApp(Activity ctx) {
		// TODO Auto-generated constructor stub
		DBManager db = new DBManager(ctx);
		WebAuth webAuth = db.getWebAuth();
		if( webAuth != null){
			username = webAuth.userName;
			password = webAuth.password;
			wlanacip = webAuth.wlanacip;
			wlanacname = webAuth.wlanacname;
			wlanuserip = webAuth.wlanuserip;
			loginurl = webAuth.loginurl;
			logonsessid = webAuth.logonsessid;
		}
		db.release();
	}
}
